#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
int dics[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int n,m;
    int Eat(vector<vector<char>>& board,int i,int j)
    {
        int ret=0;
        for(auto dic:dics)
        {
            int x=i+dic[0],y=j+dic[1];
            while(x>=0&&x<m&&y>=0&&y<n)
            {
                if(board[x][y]=='B') break;
                else if(board[x][y]=='p')
                {
                    ++ret;
                    break;
                }
                x+=dic[0],y+=dic[1];
            }
        }
        return ret;
    }

    int numRookCaptures(vector<vector<char>>& board) {
        m=board.size(),n=board[0].size();
        for(int i=0;i<m;++i)
        {
            for(int j=0;j<n;++j)
            {
                if(board[i][j]=='R')
                {
                    return Eat(board,i,j);
                }
            }
        }
        return 0;
    }
};
